package edu.sctu.practice.class02.lvchang.testArraySort;

import java.util.Arrays;
import java.util.Scanner;

/**
 * Created by Administrator on 2015/10/25.
 */
public class ArraySortDemo {

    public static void main(String[] args) {

        Scanner input = new Scanner(System.in);

        System.out.println("请输入您需要排序的5个整数：");

        int[] arrays = new int[5];

        for (int i = 0; i < 5; i++) {
            int a = input.nextInt();
            arrays[i] = a;
        }

        Arrays.sort(arrays);

        System.out.println("排序后的结果为(for循环)：");
        /**
         * 用for循环输出数组元素
         */
        for (int i = 0; i < arrays.length; i++) {
            System.out.print(arrays[i] + "  ");
        }

        System.out.println();

        System.out.println("排序后的结果为(foreach遍历)：");
        /**
         * 用foreach输出数组元素
         */
        for (int array : arrays) {
            System.out.print(array + "  ");
        }

    }
}
